/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hibernate;

import com.partaljevic.gambling.beans.Team;
import com.partaljevic.tapestry.gambling.service.TeamService;
import java.io.Serializable;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;

/**
 *
 * @author Nemanja
 */
public class TeamServiceHibernate implements TeamService{

    private final Session session;

    public TeamServiceHibernate(Session session) {
        this.session = session;
    }

    @Override
    public Team save(Team team) {
        return (Team) session.get(Team.class, session.save(team));
    }

    @Override
    public List<Team> retreive() {
        Criteria criteria = session.createCriteria(Team.class);
        return criteria.list();
    }

    @Override
    public Team retreive(Serializable id) {
        return (Team) session.get(Team.class, id);
    }

    @Override
    public void update(Team t) {
        session.saveOrUpdate(t);
    }

}
